package com.lineage.data.item_etcitem;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ItemStatus;
import com.lineage.server.serverpackets.S_PacketBoxGree;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.utils.log.PlayerLogUtil;
import com.lineage.server.world.World;
import com.lineage.william.New_BlessItem;
import java.sql.Timestamp;
import java.util.Random;

public class Reel_item_bless_armor extends ItemExecutor {
  private int _xianzhi = 0;
  
  private boolean type2 = false;
  
  public static ItemExecutor get() {
    return new Reel_item_bless_armor();
  }
  
  public static void 祝福升级成功(String info) {
    PlayerLogUtil.writeLog("[祝福升级成功]", info);
  }
  
  public static void 祝福升级失败(String info) {
    PlayerLogUtil.writeLog("[祝福升级失败]", info);
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    int itemobj = data[0];
    L1ItemInstance item2 = pc.getInventory().getItem(itemobj);
    if (item2 == null)
      return; 
    if (item2.getItem().getUseType() != 2 && item2.getItem().getUseType() != 18 && 
      item2.getItem().getUseType() != 19 && item2.getItem().getUseType() != 20 && 
      item2.getItem().getUseType() != 21 && item2.getItem().getUseType() != 22 && 
      item2.getItem().getUseType() != 25) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("该物品不是防具无法祝福"));
      return;
    } 
    if (item2.getBless() == 0 || item2.getBless() == 128) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("已经是祝福的物品"));
      return;
    } 
    if (!item2.getItem().isgivebless()) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("该物品无法进行祝福。"));
      return;
    } 
    if (item2.getBless() == 2) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("该物品是诅咒品,无法祝福"));
      return;
    } 
    Random _random = new Random();
    if (_random.nextInt(99) + 1 <= this._xianzhi) {
      New_BlessItem.forIntensifyArmor(pc, item2);
      item2.setBless(0);
      pc.getInventory().updateItem(item2, 576);
      pc.getInventory().saveItem(item2, 576);
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("祝福成功"));
      if (!pc.isGm())
        World.get().broadcastPacketToAll((ServerBasePacket)new S_PacketBoxGree(2, "玩家：" + pc.getName() + " 使用(" + item.getName() + ") 对 (" + item2.getViewName() + ")升级成功")); 
      pc.getInventory().removeItem(item, 1L);
      pc.sendPackets((ServerBasePacket)new S_ItemStatus(item2));
      祝福升级成功("玩家 :" + pc.getName() + " 使用(" + item.getName() + ") 对 (" + item2.getViewName() + ")升级成功 ,时间:" + 
          new Timestamp(System.currentTimeMillis()) + ")");
    } else {
      pc.getInventory().removeItem(item, 1L);
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("祝福失败"));
      if (!pc.isGm()) {
        World.get().broadcastPacketToAll((ServerBasePacket)new S_PacketBoxGree(2, "玩家：" + pc.getName() + " 使用(" + item.getName() + ") 对 (" + item2.getViewName() + ")升级失败"));
        World.get().broadcastPacketToAll((ServerBasePacket)new S_ServerMessage("玩家：" + pc.getName() + " 使用(" + item.getName() + ") 对 (" + item2.getViewName() + ")升级失败"));
      } 
      祝福升级失败("玩家 :" + pc.getName() + " 使用(" + item.getName() + ") 对 (" + item2.getViewName() + ")升级(失败) ,时间:" + 
          new Timestamp(System.currentTimeMillis()) + ")");
      if (this.type2)
        pc.getInventory().removeItem(item2, 1L); 
    } 
  }
  
  public void set_set(String[] set) {
    try {
      this._xianzhi = Integer.parseInt(set[1]);
    } catch (Exception exception) {}
    try {
      this.type2 = Boolean.parseBoolean(set[2]);
    } catch (Exception exception) {}
  }
}
